from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm

from Products.CMFCore.utils import getToolByName

log = __import__("logging").getLogger("apkn.repository.setup")

def GroupsVocabulary(context): 

    items = []
    
    gtool = getToolByName(context, 'portal_groups')
    items.append( (str(0), "--") )
    for group in gtool.listGroups():
        items.append((group.getId(), group.title_or_id()))
            
    terms = [ SimpleTerm(value=pair[0], token=pair[0], title=pair[1]) for pair in items ]  

    return SimpleVocabulary(terms)
